home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / comm / revrdist.sit / RevRdist / RevRdist src / RevRdist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-27  |  5.7 KB  |  257 lines  |  [TEXT/KAHL]

  1. /*
  2.  * RevRdist.c - the main routines for RevRdist
  3.  *
  4.  * RevRdist is intended to be similar in utility to the BSD Unix program
  5.  * "rdist".
  6.  * That is, it uses a file of distribution rules ("distfile") to keep
  7.  * the files and folders on client volumes synchronized with those on a
  8.  * server volume.
  9.  * That is about the end of the similarity.
  10.  * RevRdist runs on the client systems, which are assumed to be the
  11.  * student/worker Mac workstations in an AppleShare network.
  12.  * The server volume is assumed to reside on an AppleShare server.
  13.  * RevRdist itself should be in the System Folder of each client, as should
  14.  * its settings file "RevRdist prefs".
  15.  * The prefs file gives the location of the control file, which can be on the
  16.  * client or server.
  17.  * RevRdist normally runs only at reboot time.  It contains an INIT which
  18.  * checks the prefs file to see if it is time to run the full RevRdist.
  19.  * If so, RevRdist is temporarily made the startup application.
  20.  * RevRdist can also be run at any time just by launching it as an ordinary
  21.  * application.
  22.  */
  23.  
  24. #include "RevRdist.h"
  25. #include <TransSkelProto.h>
  26. #include <TransDisplayProto.h>
  27. #include "dispatch.h"
  28.  
  29. Boolean checkAbort (EventRecord *);
  30. void doAbout (void);
  31. void doEditMenu (Integer);
  32. void doFileMenu (Integer);
  33. void main (void);
  34.  
  35.  
  36. /*
  37.  *=========================================================================
  38.  * checkAbort (e) - check event for <command>-. and set quit flag if needed
  39.  *=========================================================================
  40.  */
  41.  
  42. static
  43. Boolean
  44. checkAbort (theEvent)
  45.     EventRecord *theEvent;
  46. {
  47.     if ( theEvent->what == keyDown
  48.     &&     (theEvent->message & 0xff) == '.'
  49.     &&  (theEvent->modifiers & cmdKey)
  50.        )
  51.     {
  52.         Quit = true;
  53.         return true;
  54.     }
  55.     return false;
  56. }
  57.  
  58.  
  59.  
  60. /*
  61.  *=========================================================================
  62.  * doAbout () - handle About box (using TextDialog routine from net)
  63.  *=========================================================================
  64.  */
  65.  
  66. static
  67. void
  68. doAbout ()
  69. {
  70.     Handle    theText;
  71.     
  72.     theText = GetResource (TYPE_TEXT, RSRC_ABOUT);
  73.     if (theText)
  74.     {
  75.         HLock (theText);
  76.         TextDialog (WIND_ABOUT + RSRC_BASE, theText, 1, 9, true);
  77.         HUnlock (theText);
  78.         ReleaseResource (theText);
  79.     }
  80. }
  81.  
  82.  
  83.  
  84. /*
  85.  *=========================================================================
  86.  * doEditMenu (item) - handle selection from the Edit menu
  87.  * entry:    item = selected item number
  88.  *=========================================================================
  89.  */
  90. static
  91. void
  92. doEditMenu (item)
  93.     Integer            item;
  94. {
  95.     DialogPtr        w;
  96.  
  97.     w = (DialogPtr) FrontWindow ();
  98.     if (w)
  99.     {
  100.         if (w == (DialogPtr) PrefDialog)
  101.         {
  102.             switch (item)
  103.             {
  104.             case EDT_CUT:    DlgCut (w);        break;
  105.             case EDT_COPY:    DlgCopy (w);    break;
  106.             case EDT_PASTE:    DlgPaste (w);    break;
  107.             case EDT_CLEAR:    DlgDelete (w);    break;
  108.             }
  109.         }
  110.     }
  111. }
  112.  
  113.  
  114.  
  115. /*
  116.  *=========================================================================
  117.  * doFileMenu (item) - handle selection from the File menu
  118.  * entry:    item = selected item number
  119.  *=========================================================================
  120.  */
  121. static
  122. void
  123. doFileMenu (item)
  124. Integer    item;
  125. {
  126.     WindowPtr        w;
  127.  
  128.     switch (item)
  129.     {
  130.     case FILE_OPEN:
  131.     case FILE_SAVE:
  132.     case FILE_SAVEAS:
  133.         w = FrontWindow ();
  134.         if (w && w == PrefDialog)
  135.             prefDoFMenu (item);
  136.         break;
  137.     case FILE_QUIT:
  138.         Quit = true;
  139.         if (Pause == S_PAUSED)
  140.             Pause = S_RUNNING;
  141.         break;
  142.     }
  143. }
  144.  
  145.  
  146.  
  147. /*
  148.  *=========================================================================
  149.  * doWindowMenu (item) - handle selection from window menu
  150.  * entry:    item = menu selection number
  151.  *=========================================================================
  152.  */
  153.  
  154. void
  155. doWindowMenu (item)
  156. Integer    item;
  157. {
  158.     WindowPtr w;
  159.  
  160.     switch (item)
  161.     {
  162.     case WIND_STATUS:    w = StatusDialog;    break;
  163.     case WIND_ACTIVITY:    w = ActivityWind;    break;
  164.     case WIND_ERRORS:    w = ErrorWind;        break;
  165.     case WIND_PREF:        w = PrefDialog;
  166.                         Pending = PA_PREF;    break;
  167.     default:            w = nil;
  168.     }
  169.     if (w)
  170.     {
  171.         SelectWindow (w);
  172.         ShowWindow (w);
  173.     }
  174. }
  175.  
  176.  
  177.  
  178.  
  179. /*
  180.  *=========================================================================
  181.  * main () - Set things up and turn control over to SkelMain ()
  182.  *=========================================================================
  183.  */
  184.  
  185.  
  186. static unsigned char    nullstr[1] = { 0 };
  187. void
  188. main ()
  189. {
  190.     Handle        h;
  191.     MenuHandle    m;
  192.     short result;
  193.     Str255        s;
  194.  
  195.     NullStr = nullstr;
  196.     SkelInit (6, nil);                /* initialize */
  197.     /*
  198.      * Set up our menus: Apple, File, Edit (inactive), and Windows
  199.      */
  200.     m = GetMenu (1);                /* Apple */
  201.     if (!m)
  202.         goto abandon;
  203.     GetItem (m, 1, s);                /* About... text */
  204.     SkelApple (s, doAbout);            /* handle desk accessories */
  205.  
  206.     m = GetMenu (2);                /* File */
  207.     if (!m)
  208.         goto abandon;
  209.     if (!SkelMenu (m, doFileMenu, nil, false))
  210.         goto abandon;
  211.     DisableItem (m, FILE_OPEN);
  212.     DisableItem (m, FILE_SAVE);
  213.     DisableItem (m, FILE_SAVEAS);
  214.  
  215.     m = GetMenu (3);                /* Edit */
  216.     if (!m)
  217.         goto abandon;
  218.     if (!SkelMenu (m, doEditMenu, nil, false))
  219.         goto abandon;
  220.     DisableItem (m, 0);                /* disable it */
  221.         
  222.     m = GetMenu (4);                /* Window */
  223.     if (!m)
  224.         goto abandon;
  225.     if (!SkelMenu (m, doWindowMenu, nil, false))
  226.         goto abandon;
  227.     DisableItem (m, 0);                /* disable it for now */
  228.     DrawMenuBar ();
  229.  
  230.     initGlobals ();
  231.     if (!Quit)                        /* if initialized okay */
  232.     {
  233.         if (Flags & DB_LOCKED)
  234.             DisableItem (m, WIND_PREF);    /* if locked, can't do prefs */
  235.         EnableItem (m, 0);            /* Okay to enable Windows now */
  236.         DrawMenuBar ();
  237.  
  238.         SkelEventHook (checkAbort);
  239.         SkelBackground (dispatch);
  240.  
  241.         Pending = PA_PREF;
  242.         if ((Flags & DB_STARTUP)
  243.         ||    File_list[FL_PREF].f_launch
  244.         ||  File_list[FL_DIST].f_launch)
  245.             Pending = PA_GO;
  246.  
  247.         showstat ();
  248.         result = pushCall (idle, nil);
  249.         if (result == R_CONT)
  250.             SkelMain ();
  251.     }
  252. abandon:
  253.     SkelClobber ();                    /* clean up */
  254.     tidyUp ();                        /* more clean up */
  255.     if (Flags & DB_STARTUP)            /* if boot application, reboot */
  256.         ShutDwnStart ();
  257. }